/*
 * XXX
 */

package edu.uhcl.csci4838.group3.widget;

import java.util.Calendar;
import java.util.GregorianCalendar;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.format.DateFormat;
import android.util.AttributeSet;
import android.widget.Button;

/**
 * XXX
 * 
 * @author Chris Waguespack
 */
public class DateButton extends Button implements Parcelable {
	
	private int day;
	private int month;
	private int year;
	
	/**
	 * XXX
	 * 
	 * @param context
	 */
	public DateButton(final Context context) {
		super(context);
		this.setCurrentTime();
	}
	
	/**
	 * XXX
	 * 
	 * @param context
	 * @param attrs
	 */
	public DateButton(final Context context,
			final AttributeSet attrs) {
		super(context,
				attrs);
		this.setCurrentTime();
	}
	
	/**
	 * XXX
	 * 
	 * @param context
	 * @param attrs
	 * @param defStyle
	 */
	public DateButton(final Context context,
			final AttributeSet attrs,
			final int defStyle) {
		super(context,
				attrs,
				defStyle);
		this.setCurrentTime();
	}
	
	/**
	 * XXXs
	 */
	private void setCurrentTime() {
		Calendar cal = Calendar.getInstance();
		month = cal.get(Calendar.MONTH);
		day = cal.get(Calendar.DAY_OF_MONTH);
		year = cal.get(Calendar.YEAR);
		updateText();
	}
	
	private void updateText() {
		this.setText(DateFormat.format("MM/dd/yyyy",
				new GregorianCalendar(year, month, day)));
	}

	/**
	 * XXX
	 * 
	 * @return
	 */
	/* 
	 * (non-Javadoc)
	 * 
	 * @see android.os.Parcelable#describeContents()
	 */
	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * XXX
	 * 
	 * @param dest
	 * @param flags
	 */
	/* 
	 * (non-Javadoc)
	 * 
	 * @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
	 */
	@Override
	public void writeToParcel(Parcel dest,
			int flags) {
		// TODO Auto-generated method stub
	}

	/**
	 * Returns XXX.
	 * 
	 * @return XXX
	 * @see #setXXX
	 */
	public int getDay() {
		return this.day;
	}

	/**
	 * Sets XXX.
	 * 
	 * @param day XXX
	 * @see #getXXX
	 */
	public void setDay(int day) {
		this.day = day;
		updateText();
	}

	/**
	 * Returns XXX.
	 * 
	 * @return XXX
	 * @see #setXXX
	 */
	public int getMonth() {
		return this.month;
	}

	/**
	 * Sets XXX.
	 * 
	 * @param month XXX
	 * @see #getXXX
	 */
	public void setMonth(int month) {
		this.month = month;
		updateText();
	}

	/**
	 * Returns XXX.
	 * 
	 * @return XXX
	 * @see #setXXX
	 */
	public int getYear() {
		return this.year;
	}

	/**
	 * Sets XXX.
	 * 
	 * @param year XXX
	 * @see #getXXX
	 */
	public void setYear(int year) {
		this.year = year;
		updateText();
	}
	
}
